<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Dom和Bom复习-cnblog | 凌歆的博客</title>
    <meta name="generator" content="VuePress 1.9.5">
    <link rel="icon" href="/img/favicon.ico">
    <meta name="description" content="web前端技术博客,专注web前端学习与总结。JavaScript,js,ES6,TypeScript,vue,React,python,css3,html5,Node,git,github等技术文章。">
    <meta name="keywords" content="前端博客,个人技术博客,前端,前端开发,前端框架,web前端,前端面试题,技术文档,学习,面试,JavaScript,js,ES6,TypeScript,vue,python,css3,html5,Node,git,github,markdown">
    <meta name="baidu-site-verification" content="7F55weZDDc">
    <meta name="theme-color" content="#11a8cd">
    
    <link rel="preload" href="/assets/css/0.styles.d9c8cf8c.css" as="style"><link rel="preload" href="/assets/js/app.57550e13.js" as="script"><link rel="preload" href="/assets/js/2.f014c35f.js" as="script"><link rel="preload" href="/assets/js/125.f073ab1c.js" as="script"><link rel="prefetch" href="/assets/js/10.03a98811.js"><link rel="prefetch" href="/assets/js/100.145e708e.js"><link rel="prefetch" href="/assets/js/101.098ca5c8.js"><link rel="prefetch" href="/assets/js/102.4d45c69a.js"><link rel="prefetch" href="/assets/js/103.499de505.js"><link rel="prefetch" href="/assets/js/104.c2c1b9b6.js"><link rel="prefetch" href="/assets/js/105.4e9b0663.js"><link rel="prefetch" href="/assets/js/106.9bb8cf6f.js"><link rel="prefetch" href="/assets/js/107.a81b32d7.js"><link rel="prefetch" href="/assets/js/108.81511e67.js"><link rel="prefetch" href="/assets/js/109.6a6741bf.js"><link rel="prefetch" href="/assets/js/11.e8729182.js"><link rel="prefetch" href="/assets/js/110.de657fe7.js"><link rel="prefetch" href="/assets/js/111.b092af6d.js"><link rel="prefetch" href="/assets/js/112.2dca5709.js"><link rel="prefetch" href="/assets/js/113.dbed1fac.js"><link rel="prefetch" href="/assets/js/114.e95a0131.js"><link rel="prefetch" href="/assets/js/115.2e3e8285.js"><link rel="prefetch" href="/assets/js/116.e64f7fec.js"><link rel="prefetch" href="/assets/js/117.583552c9.js"><link rel="prefetch" href="/assets/js/118.aa5d18f0.js"><link rel="prefetch" href="/assets/js/119.0c7b52d7.js"><link rel="prefetch" href="/assets/js/12.d63acec2.js"><link rel="prefetch" href="/assets/js/120.13f86281.js"><link rel="prefetch" href="/assets/js/121.e2b5b7f9.js"><link rel="prefetch" href="/assets/js/122.5252216a.js"><link rel="prefetch" href="/assets/js/123.8b8a3503.js"><link rel="prefetch" href="/assets/js/124.60df855c.js"><link rel="prefetch" href="/assets/js/126.7b73de6a.js"><link rel="prefetch" href="/assets/js/127.4e25971c.js"><link rel="prefetch" href="/assets/js/128.0edf0e06.js"><link rel="prefetch" href="/assets/js/129.5cb5a70a.js"><link rel="prefetch" href="/assets/js/13.2259ef71.js"><link rel="prefetch" href="/assets/js/130.00247fda.js"><link rel="prefetch" href="/assets/js/131.d6fc003a.js"><link rel="prefetch" href="/assets/js/132.1a32b18f.js"><link rel="prefetch" href="/assets/js/133.e46c0193.js"><link rel="prefetch" href="/assets/js/134.a6ad681f.js"><link rel="prefetch" href="/assets/js/135.2fcbe137.js"><link rel="prefetch" href="/assets/js/136.f69bf451.js"><link rel="prefetch" href="/assets/js/137.b9ef2fcc.js"><link rel="prefetch" href="/assets/js/138.7fdd9feb.js"><link rel="prefetch" href="/assets/js/139.a3a37c91.js"><link rel="prefetch" href="/assets/js/14.0d6b23b9.js"><link rel="prefetch" href="/assets/js/140.a7c013ae.js"><link rel="prefetch" href="/assets/js/141.956c36ce.js"><link rel="prefetch" href="/assets/js/142.5aacfe42.js"><link rel="prefetch" href="/assets/js/143.57d691ef.js"><link rel="prefetch" href="/assets/js/144.b1e5766e.js"><link rel="prefetch" href="/assets/js/145.463284b7.js"><link rel="prefetch" href="/assets/js/146.6cc6420c.js"><link rel="prefetch" href="/assets/js/147.5b78c5a2.js"><link rel="prefetch" href="/assets/js/148.8d1d7679.js"><link rel="prefetch" href="/assets/js/149.4e0eb213.js"><link rel="prefetch" href="/assets/js/15.f6fde69d.js"><link rel="prefetch" href="/assets/js/150.b183de37.js"><link rel="prefetch" href="/assets/js/151.729ae770.js"><link rel="prefetch" href="/assets/js/152.b1297018.js"><link rel="prefetch" href="/assets/js/153.bb991bca.js"><link rel="prefetch" href="/assets/js/154.6f2286aa.js"><link rel="prefetch" href="/assets/js/155.6a9c7e4d.js"><link rel="prefetch" href="/assets/js/156.f7bd535d.js"><link rel="prefetch" href="/assets/js/157.64c0065c.js"><link rel="prefetch" href="/assets/js/158.d31ae949.js"><link rel="prefetch" href="/assets/js/159.7daea8a7.js"><link rel="prefetch" href="/assets/js/16.7be21beb.js"><link rel="prefetch" href="/assets/js/160.33cc971a.js"><link rel="prefetch" href="/assets/js/161.1676442a.js"><link rel="prefetch" href="/assets/js/162.71378046.js"><link rel="prefetch" href="/assets/js/163.99e49959.js"><link rel="prefetch" href="/assets/js/164.306f07d2.js"><link rel="prefetch" href="/assets/js/165.170977c7.js"><link rel="prefetch" href="/assets/js/166.f8602525.js"><link rel="prefetch" href="/assets/js/167.eea5c001.js"><link rel="prefetch" href="/assets/js/168.0146a311.js"><link rel="prefetch" href="/assets/js/169.05f9c9d9.js"><link rel="prefetch" href="/assets/js/17.2543f471.js"><link rel="prefetch" href="/assets/js/170.25d602b2.js"><link rel="prefetch" href="/assets/js/171.1ada26a6.js"><link rel="prefetch" href="/assets/js/172.2a0f697c.js"><link rel="prefetch" href="/assets/js/173.230d8ca8.js"><link rel="prefetch" href="/assets/js/174.e3758a2b.js"><link rel="prefetch" href="/assets/js/175.0f19f8ea.js"><link rel="prefetch" href="/assets/js/176.bf70d37d.js"><link rel="prefetch" href="/assets/js/177.4400f272.js"><link rel="prefetch" href="/assets/js/178.85af7b89.js"><link rel="prefetch" href="/assets/js/179.4cfaaaa2.js"><link rel="prefetch" href="/assets/js/18.394415f8.js"><link rel="prefetch" href="/assets/js/180.449c8409.js"><link rel="prefetch" href="/assets/js/181.73276924.js"><link rel="prefetch" href="/assets/js/182.5fab25cc.js"><link rel="prefetch" href="/assets/js/183.ecd4934d.js"><link rel="prefetch" href="/assets/js/184.246092cf.js"><link rel="prefetch" href="/assets/js/185.c671cd86.js"><link rel="prefetch" href="/assets/js/186.49bd1963.js"><link rel="prefetch" href="/assets/js/187.1fb32764.js"><link rel="prefetch" href="/assets/js/188.7c6885e9.js"><link rel="prefetch" href="/assets/js/189.a8701dec.js"><link rel="prefetch" href="/assets/js/19.ca7db8ea.js"><link rel="prefetch" href="/assets/js/190.ae3d3bde.js"><link rel="prefetch" href="/assets/js/191.ad7cd44e.js"><link rel="prefetch" href="/assets/js/192.bc443842.js"><link rel="prefetch" href="/assets/js/193.e4755764.js"><link rel="prefetch" href="/assets/js/194.814112ce.js"><link rel="prefetch" href="/assets/js/195.1c0aaa80.js"><link rel="prefetch" href="/assets/js/196.a6bd7add.js"><link rel="prefetch" href="/assets/js/20.4e91cd31.js"><link rel="prefetch" href="/assets/js/21.f095e6e1.js"><link rel="prefetch" href="/assets/js/22.72f4b8ab.js"><link rel="prefetch" href="/assets/js/23.e94eb9d2.js"><link rel="prefetch" href="/assets/js/24.0eae7d6f.js"><link rel="prefetch" href="/assets/js/25.36157609.js"><link rel="prefetch" href="/assets/js/26.dc5b6cba.js"><link rel="prefetch" href="/assets/js/27.c19b7b63.js"><link rel="prefetch" href="/assets/js/28.3aceae59.js"><link rel="prefetch" href="/assets/js/29.536091b3.js"><link rel="prefetch" href="/assets/js/3.d11119c4.js"><link rel="prefetch" href="/assets/js/30.821a4a30.js"><link rel="prefetch" href="/assets/js/31.5238784c.js"><link rel="prefetch" href="/assets/js/32.10bc7179.js"><link rel="prefetch" href="/assets/js/33.c1ed69c9.js"><link rel="prefetch" href="/assets/js/34.8d384231.js"><link rel="prefetch" href="/assets/js/35.d8890e52.js"><link rel="prefetch" href="/assets/js/36.eca37ad5.js"><link rel="prefetch" href="/assets/js/37.802549e3.js"><link rel="prefetch" href="/assets/js/38.53841770.js"><link rel="prefetch" href="/assets/js/39.7ae44409.js"><link rel="prefetch" href="/assets/js/4.493b9bca.js"><link rel="prefetch" href="/assets/js/40.ce56364a.js"><link rel="prefetch" href="/assets/js/41.85f0114b.js"><link rel="prefetch" href="/assets/js/42.714da6e2.js"><link rel="prefetch" href="/assets/js/43.fee4437c.js"><link rel="prefetch" href="/assets/js/44.b039b68b.js"><link rel="prefetch" href="/assets/js/45.96a55605.js"><link rel="prefetch" href="/assets/js/46.956ffb03.js"><link rel="prefetch" href="/assets/js/47.147d9218.js"><link rel="prefetch" href="/assets/js/48.ff787b40.js"><link rel="prefetch" href="/assets/js/49.871eee87.js"><link rel="prefetch" href="/assets/js/5.e0ba07d7.js"><link rel="prefetch" href="/assets/js/50.99b7c29e.js"><link rel="prefetch" href="/assets/js/51.8ecbf4ba.js"><link rel="prefetch" href="/assets/js/52.53d91d7e.js"><link rel="prefetch" href="/assets/js/53.af8a0d2a.js"><link rel="prefetch" href="/assets/js/54.a2f848b5.js"><link rel="prefetch" href="/assets/js/55.267e9947.js"><link rel="prefetch" href="/assets/js/56.0b201c40.js"><link rel="prefetch" href="/assets/js/57.cbdfd6f7.js"><link rel="prefetch" href="/assets/js/58.636c0c3f.js"><link rel="prefetch" href="/assets/js/59.fc9216c4.js"><link rel="prefetch" href="/assets/js/6.b98373f2.js"><link rel="prefetch" href="/assets/js/60.34f16fc4.js"><link rel="prefetch" href="/assets/js/61.4d130bd8.js"><link rel="prefetch" href="/assets/js/62.927caa10.js"><link rel="prefetch" href="/assets/js/63.a451fee0.js"><link rel="prefetch" href="/assets/js/64.32a5d47b.js"><link rel="prefetch" href="/assets/js/65.bc099429.js"><link rel="prefetch" href="/assets/js/66.3953050d.js"><link rel="prefetch" href="/assets/js/67.e934823b.js"><link rel="prefetch" href="/assets/js/68.4bcb52b0.js"><link rel="prefetch" href="/assets/js/69.bede18c8.js"><link rel="prefetch" href="/assets/js/7.8de8df2d.js"><link rel="prefetch" href="/assets/js/70.fce1daac.js"><link rel="prefetch" href="/assets/js/71.ea0a8c5d.js"><link rel="prefetch" href="/assets/js/72.15382c9e.js"><link rel="prefetch" href="/assets/js/73.848364d3.js"><link rel="prefetch" href="/assets/js/74.5fd08a50.js"><link rel="prefetch" href="/assets/js/75.c937c70d.js"><link rel="prefetch" href="/assets/js/76.a0dacd5a.js"><link rel="prefetch" href="/assets/js/77.4019cc23.js"><link rel="prefetch" href="/assets/js/78.9676a9e1.js"><link rel="prefetch" href="/assets/js/79.e46e10d5.js"><link rel="prefetch" href="/assets/js/8.2098eb96.js"><link rel="prefetch" href="/assets/js/80.987e83cb.js"><link rel="prefetch" href="/assets/js/81.eb98ff36.js"><link rel="prefetch" href="/assets/js/82.623561a7.js"><link rel="prefetch" href="/assets/js/83.e256d909.js"><link rel="prefetch" href="/assets/js/84.7d06a550.js"><link rel="prefetch" href="/assets/js/85.b8d9879e.js"><link rel="prefetch" href="/assets/js/86.31c4581b.js"><link rel="prefetch" href="/assets/js/87.e06ee05e.js"><link rel="prefetch" href="/assets/js/88.81ef718d.js"><link rel="prefetch" href="/assets/js/89.ba237d2f.js"><link rel="prefetch" href="/assets/js/9.36092fd0.js"><link rel="prefetch" href="/assets/js/90.ad2c9d92.js"><link rel="prefetch" href="/assets/js/91.a661f52d.js"><link rel="prefetch" href="/assets/js/92.1c28035b.js"><link rel="prefetch" href="/assets/js/93.c8b8e3d6.js"><link rel="prefetch" href="/assets/js/94.b6bc4a44.js"><link rel="prefetch" href="/assets/js/95.92cea882.js"><link rel="prefetch" href="/assets/js/96.5373491b.js"><link rel="prefetch" href="/assets/js/97.bb39efc8.js"><link rel="prefetch" href="/assets/js/98.af7a030f.js"><link rel="prefetch" href="/assets/js/99.07dc87d8.js">
    <link rel="stylesheet" href="/assets/css/0.styles.d9c8cf8c.css">
  </head>
  <body class="theme-mode-light">
    <div id="app" data-server-rendered="true"><div class="theme-container sidebar-open have-rightmenu"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="https://lingxin-tanhua.oss-cn-shanghai.aliyuncs.com/QQ%E6%88%AA%E5%9B%BE20220503092755.png" alt="凌歆的博客" class="logo"> <span class="site-name can-hide">凌歆的博客</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="前端" class="dropdown-title"><a href="/web/" class="link-title">前端</a> <span class="title" style="display:none;">前端</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>学习笔记</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/note/html/" class="nav-link">HTML笔记</a></li><li class="dropdown-subitem"><a href="/note/js-low/" class="nav-link">JavaScript基础笔记</a></li><li class="dropdown-subitem"><a href="/note/js-high/" class="nav-link">JavaScript高阶笔记</a></li><li class="dropdown-subitem"><a href="/note/js-dom-bom/" class="nav-link">JavaScript DOM和BOM笔记</a></li><li class="dropdown-subitem"><a href="/note/jquery/" class="nav-link">jQuery笔记</a></li><li class="dropdown-subitem"><a href="/note/ajax/" class="nav-link">Ajax笔记</a></li><li class="dropdown-subitem"><a href="/note/nodejs/" class="nav-link">NodeJs笔记</a></li><li class="dropdown-subitem"><a href="/note/reg/" class="nav-link">正则表达式笔记</a></li><li class="dropdown-subitem"><a href="/note/vue/" class="nav-link">Vue笔记</a></li><li class="dropdown-subitem"><a href="/note/react/" class="nav-link">react笔记</a></li><li class="dropdown-subitem"><a href="/note/wx/" class="nav-link">微信小程序笔记</a></li><li class="dropdown-subitem"><a href="/note/uniapp/" class="nav-link">uniapp笔记</a></li><li class="dropdown-subitem"><a href="/note/echarts/" class="nav-link">echarts笔记</a></li><li class="dropdown-subitem"><a href="/note/git/" class="nav-link">Git笔记</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="后端" class="dropdown-title"><a href="/back/" class="link-title">后端</a> <span class="title" style="display:none;">后端</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/note/java/" class="nav-link">JAVA</a></li><li class="dropdown-item"><!----> <a href="/note/javaweb/" class="nav-link">JavaWeb</a></li><li class="dropdown-item"><!----> <a href="/note/mysql/" class="nav-link">MySql</a></li><li class="dropdown-item"><!----> <a href="/note/ssm/" class="nav-link">ssm</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="算法" class="dropdown-title"><a href="/algor/" class="link-title">算法</a> <span class="title" style="display:none;">算法</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/note/sf/" class="nav-link">算法训练营</a></li><li class="dropdown-item"><!----> <a href="/note/js-sf/" class="nav-link">js数据结构与算法</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="面试" class="dropdown-title"><a href="/mianshi/" class="link-title">面试</a> <span class="title" style="display:none;">面试</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/note/lqb/" class="nav-link">蓝桥杯备战</a></li><li class="dropdown-item"><!----> <a href="/note/ms/" class="nav-link">前端面试</a></li><li class="dropdown-item"><!----> <a href="/note/hmms/" class="nav-link">黑马面试</a></li><li class="dropdown-item"><!----> <a href="/note/xzms/" class="nav-link">校招零距离面试</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="解决方案" class="dropdown-title"><a href="/resolve/" class="link-title">解决方案</a> <span class="title" style="display:none;">解决方案</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/note/qd-resolve/" class="nav-link">前端解决方案</a></li><li class="dropdown-item"><!----> <a href="/note/hd-resolve/" class="nav-link">后端解决方案</a></li></ul></div></div><div class="nav-item"><a href="/pages/beb6c0bd8a66cea6/" class="nav-link">收藏</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">归档</a></li></ul></div></div> <a href="https://github.com/linxin1123/vuepress-blog" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar-hover-trigger"></div> <aside class="sidebar" style="display:none;"><div class="blogger"><img src="https://lingxin-tanhua.oss-cn-shanghai.aliyuncs.com/QQ%E6%88%AA%E5%9B%BE20220503092755.png"> <div class="blogger-info"><h3>lingxin</h3> <span>凌歆</span></div></div> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="前端" class="dropdown-title"><a href="/web/" class="link-title">前端</a> <span class="title" style="display:none;">前端</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>学习笔记</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/note/html/" class="nav-link">HTML笔记</a></li><li class="dropdown-subitem"><a href="/note/js-low/" class="nav-link">JavaScript基础笔记</a></li><li class="dropdown-subitem"><a href="/note/js-high/" class="nav-link">JavaScript高阶笔记</a></li><li class="dropdown-subitem"><a href="/note/js-dom-bom/" class="nav-link">JavaScript DOM和BOM笔记</a></li><li class="dropdown-subitem"><a href="/note/jquery/" class="nav-link">jQuery笔记</a></li><li class="dropdown-subitem"><a href="/note/ajax/" class="nav-link">Ajax笔记</a></li><li class="dropdown-subitem"><a href="/note/nodejs/" class="nav-link">NodeJs笔记</a></li><li class="dropdown-subitem"><a href="/note/reg/" class="nav-link">正则表达式笔记</a></li><li class="dropdown-subitem"><a href="/note/vue/" class="nav-link">Vue笔记</a></li><li class="dropdown-subitem"><a href="/note/react/" class="nav-link">react笔记</a></li><li class="dropdown-subitem"><a href="/note/wx/" class="nav-link">微信小程序笔记</a></li><li class="dropdown-subitem"><a href="/note/uniapp/" class="nav-link">uniapp笔记</a></li><li class="dropdown-subitem"><a href="/note/echarts/" class="nav-link">echarts笔记</a></li><li class="dropdown-subitem"><a href="/note/git/" class="nav-link">Git笔记</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="后端" class="dropdown-title"><a href="/back/" class="link-title">后端</a> <span class="title" style="display:none;">后端</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/note/java/" class="nav-link">JAVA</a></li><li class="dropdown-item"><!----> <a href="/note/javaweb/" class="nav-link">JavaWeb</a></li><li class="dropdown-item"><!----> <a href="/note/mysql/" class="nav-link">MySql</a></li><li class="dropdown-item"><!----> <a href="/note/ssm/" class="nav-link">ssm</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="算法" class="dropdown-title"><a href="/algor/" class="link-title">算法</a> <span class="title" style="display:none;">算法</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/note/sf/" class="nav-link">算法训练营</a></li><li class="dropdown-item"><!----> <a href="/note/js-sf/" class="nav-link">js数据结构与算法</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="面试" class="dropdown-title"><a href="/mianshi/" class="link-title">面试</a> <span class="title" style="display:none;">面试</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/note/lqb/" class="nav-link">蓝桥杯备战</a></li><li class="dropdown-item"><!----> <a href="/note/ms/" class="nav-link">前端面试</a></li><li class="dropdown-item"><!----> <a href="/note/hmms/" class="nav-link">黑马面试</a></li><li class="dropdown-item"><!----> <a href="/note/xzms/" class="nav-link">校招零距离面试</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="解决方案" class="dropdown-title"><a href="/resolve/" class="link-title">解决方案</a> <span class="title" style="display:none;">解决方案</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/note/qd-resolve/" class="nav-link">前端解决方案</a></li><li class="dropdown-item"><!----> <a href="/note/hd-resolve/" class="nav-link">后端解决方案</a></li></ul></div></div><div class="nav-item"><a href="/pages/beb6c0bd8a66cea6/" class="nav-link">收藏</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">归档</a></li></ul></div></div> <a href="https://github.com/linxin1123/vuepress-blog" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>学习笔记</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>蓝桥杯备战</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/pages/fc8666/" class="sidebar-link">html+css部分复习-cnblog</a></li><li><a href="/pages/f57a40/" aria-current="page" class="active sidebar-link">Dom和Bom复习-cnblog</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/pages/e4078d/" class="sidebar-link">ajax复习</a></li><li><a href="/pages/731437/" class="sidebar-link">NodeJs复习-cnblog</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>前端面试</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>黑马面试</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>校招零距离面试</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <div><main class="page"><div class="theme-vdoing-wrapper "><div class="articleInfo-wrap" data-v-06225672><div class="articleInfo" data-v-06225672><ul class="breadcrumbs" data-v-06225672><li data-v-06225672><a href="/" title="首页" class="iconfont icon-home router-link-active" data-v-06225672></a></li> <li data-v-06225672><a href="/mianshi/#面试" data-v-06225672>面试</a></li><li data-v-06225672><a href="/mianshi/#蓝桥杯备战" data-v-06225672>蓝桥杯备战</a></li></ul> <div class="info" data-v-06225672><div title="作者" class="author iconfont icon-touxiang" data-v-06225672><a href="https://github.com/linxin1123" target="_blank" title="作者" class="beLink" data-v-06225672>lingxin</a></div> <div title="创建时间" class="date iconfont icon-riqi" data-v-06225672><a href="javascript:;" data-v-06225672>2023-02-17</a></div> <!----></div></div></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-title">目录</div> <div class="right-menu-content"></div></div></div> <h1><img src="">Dom和Bom复习-cnblog<!----></h1>  <div class="theme-vdoing-content content__default"><h3 id="_1-getelementsbytagname"><a href="#_1-getelementsbytagname" class="header-anchor">#</a> 1. getElementsByTagName</h3> <ul><li>返回值为一个伪数组对象（其他获取多个元素的方法也是如此）</li> <li>==注意遍历方式==</li></ul> <h3 id="_2-获取特殊元素body和html"><a href="#_2-获取特殊元素body和html" class="header-anchor">#</a> 2. 获取特殊元素body和html</h3> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">// 获取body</span>
<span class="token keyword">var</span> bodyEle<span class="token operator">=</span>document<span class="token punctuation">.</span>body

<span class="token comment">// 获取html</span>
<span class="token keyword">var</span> htmlEle<span class="token operator">=</span>document<span class="token punctuation">.</span>documentElement
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><h3 id="_3-表单元素的属性操作"><a href="#_3-表单元素的属性操作" class="header-anchor">#</a> 3. 表单元素的属性操作</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231806979-1101277398.png" alt=""></p> <h3 id="_4-事件处理函数中的this指向"><a href="#_4-事件处理函数中的this指向" class="header-anchor">#</a> 4. 事件处理函数中的this指向</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231806546-549686962.png" alt=""></p> <h3 id="_5-实现密文明文切换的解决方案"><a href="#_5-实现密文明文切换的解决方案" class="header-anchor">#</a> 5  实现密文明文切换的解决方案</h3> <ul><li>改输入框类型type(text--&gt;password)</li> <li>纯js，n个原点----&gt; 原来的内容</li></ul> <h3 id="_6-原生js操作样式的方法"><a href="#_6-原生js操作样式的方法" class="header-anchor">#</a> 6 原生JS操作样式的方法</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231805998-333077699.png" alt=""></p> <ul><li>display样式</li></ul> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231805508-751873703.png" alt=""></p> <ul><li>className注意点</li></ul> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231805177-1334230025.png" alt=""></p> <h3 id="_7-常用的事件"><a href="#_7-常用的事件" class="header-anchor">#</a> 7 .常用的事件</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231804858-441300318.png" alt=""></p> <h3 id="_8-多元素绑定事件"><a href="#_8-多元素绑定事件" class="header-anchor">#</a> 8. 多元素绑定事件</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231804377-1638559988.png" alt=""></p> <h3 id="_9-自定义属性值操作"><a href="#_9-自定义属性值操作" class="header-anchor">#</a> 9. 自定义属性值操作</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231803817-303042772.png" alt=""></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231803426-341304105.png" alt="QQ截图20230114165621"></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231802983-199607338.png" alt="QQ截图20230114165628"></p> <ul><li>setAttribute设置类名</li></ul> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231802647-718744698.png" alt=""></p> <h3 id="_10-tab栏切换"><a href="#_10-tab栏切换" class="header-anchor">#</a> 10.tab栏切换</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231802268-1366462126.png" alt=""></p> <ul><li>设置自定义属性，li标签对应每个div大盒子
<ul><li>为什么不直接用i，let的情况下可以，var i为最后一个（不行）</li> <li>解决方案
<ul><li>使用let关键字（生成闭包）</li> <li>每个li设置自定义属性，lis[i].setAttribute('index',i)</li> <li>立即执行函数（生成闭包）</li></ul></li></ul></li></ul> <h3 id="_11-h5自定义属性"><a href="#_11-h5自定义属性" class="header-anchor">#</a> 11. H5自定义属性</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231801805-641463531.png" alt=""></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231801488-857652997.png" alt="QQ截图20230114171156"></p> <ul><li>获取data-list-name类型的自定义属性</li></ul> <div class="language-js line-numbers-mode"><pre class="language-js"><code>div<span class="token punctuation">.</span>dataset<span class="token punctuation">.</span>listName
div<span class="token punctuation">.</span><span class="token function">getAttribute</span><span class="token punctuation">(</span><span class="token string">'data-list-name'</span><span class="token punctuation">)</span>
div<span class="token punctuation">.</span>dataset<span class="token punctuation">[</span><span class="token string">'data-list-name'</span><span class="token punctuation">]</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h3 id="_12-节点属性"><a href="#_12-节点属性" class="header-anchor">#</a> 12. 节点属性</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231800810-1416677819.png" alt=""></p> <h3 id="_13-节点操作"><a href="#_13-节点操作" class="header-anchor">#</a> 13. 节点操作</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231800382-320363969.png" alt=""></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231800054-1269725358.png" alt="QQ截图20230114192925"></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231759635-168862747.png" alt="QQ截图20230114192952"></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231759260-62521699.png" alt="QQ截图20230114192959"></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231758931-1986703885.png" alt="QQ截图20230114193008"></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231758481-548091449.png" alt=""></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231758026-1882969446.png" alt=""></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231757731-1428608695.png" alt="QQ截图20230114200216"></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231757424-1828940787.png" alt="QQ截图20230114200234"></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231757124-1861545084.png" alt="QQ截图20230114200246"></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231756778-788405606.png" alt="QQ截图20230114200310"></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231756276-696607373.png" alt="QQ截图20230114200526"></p> <h3 id="_14-注册事件的兼容性解决方案"><a href="#_14-注册事件的兼容性解决方案" class="header-anchor">#</a> 14. 注册事件的兼容性解决方案</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231755834-822298394.png" alt=""></p> <h3 id="_16-删除事件的兼容性解决方案"><a href="#_16-删除事件的兼容性解决方案" class="header-anchor">#</a> 16. 删除事件的兼容性解决方案</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231755430-1851055033.png" alt=""></p> <h3 id="_17-dom事件流"><a href="#_17-dom事件流" class="header-anchor">#</a> 17. DOM事件流</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231755028-608081443.png" alt=""></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231754630-328763864.png" alt="QQ截图20230115095818"></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231754211-1616292828.png" alt="QQ截图20230115095826"></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231753811-460338039.png" alt="QQ截图20230115095836"></p> <h3 id="_18-阻止事件冒泡"><a href="#_18-阻止事件冒泡" class="header-anchor">#</a> 18  阻止事件冒泡</h3> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">if</span><span class="token punctuation">(</span>e <span class="token operator">&amp;&amp;</span> e<span class="token punctuation">.</span>stopPropagation<span class="token punctuation">)</span><span class="token punctuation">{</span>
 e<span class="token punctuation">.</span><span class="token function">stopPropagation</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
 <span class="token punctuation">}</span><span class="token keyword">else</span><span class="token punctuation">{</span>
 window<span class="token punctuation">.</span>event<span class="token punctuation">.</span>cancelBubble <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span>
 <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><h3 id="_19-鼠标事件"><a href="#_19-鼠标事件" class="header-anchor">#</a> 19 鼠标事件</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231753254-328414536.png" alt=""></p> <h3 id="_20-鼠标的事件对象"><a href="#_20-鼠标的事件对象" class="header-anchor">#</a> 20  鼠标的事件对象</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231752855-629278725.png" alt=""></p> <h3 id="_21-键盘事件"><a href="#_21-键盘事件" class="header-anchor">#</a> 21. 键盘事件</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231752188-511761599.png" alt=""></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231751597-298845820.png" alt=""></p> <ul><li>注意点</li></ul> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231751237-1902740007.png" alt=""></p> <h3 id="_22-bom构成"><a href="#_22-bom构成" class="header-anchor">#</a> 22 BOM构成</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231750884-2116387780.png" alt=""></p> <h3 id="_23-窗口事件对象"><a href="#_23-窗口事件对象" class="header-anchor">#</a> 23. 窗口事件对象</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231750550-1279857213.png" alt=""></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231750119-1536613041.png" alt="QQ截图20230115183305"></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231749721-253641222.png" alt="QQ截图20230115183316"></p> <h3 id="_24-button内容修改"><a href="#_24-button内容修改" class="header-anchor">#</a> 24 button内容修改</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231749322-1630943064.png" alt=""></p> <h3 id="_25-this指向"><a href="#_25-this指向" class="header-anchor">#</a> 25 this指向</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231748955-809960352.png" alt=""></p> <h3 id="_26-js执行机制"><a href="#_26-js执行机制" class="header-anchor">#</a> 26 JS执行机制</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231748609-436628268.png" alt=""></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231748215-1142926031.png" alt="QQ截图20230115185517"></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231747757-1557796232.png" alt="QQ截图20230115185526"></p> <h3 id="_27-url"><a href="#_27-url" class="header-anchor">#</a> 27 URL</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231747317-263929041.png" alt=""></p> <h3 id="_28-location对象"><a href="#_28-location对象" class="header-anchor">#</a> 28. location对象</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231746569-709974581.png" alt=""></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231745887-1003348992.png" alt=""></p> <h3 id="_29-navigator对象"><a href="#_29-navigator对象" class="header-anchor">#</a> 29 navigator对象</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231745292-801667894.png" alt=""></p> <h3 id="_30-history对象"><a href="#_30-history对象" class="header-anchor">#</a> 30 history对象</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231744707-157274841.png" alt=""></p> <h3 id="_31-offset系列"><a href="#_31-offset系列" class="header-anchor">#</a> 31. offset系列</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231744084-68913738.png" alt=""></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231743227-2006874225.png" alt="QQ截图20230115200024"></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231742622-1428343650.png" alt="QQ截图20230115200038"></p> <h3 id="_31-offset与事件对象配合使用"><a href="#_31-offset与事件对象配合使用" class="header-anchor">#</a> 31. offset与事件对象配合使用</h3> <ul><li>点击盒子，获取点击处与盒子的距离</li></ul> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token operator">&lt;</span>script<span class="token operator">&gt;</span>
        <span class="token keyword">var</span> div<span class="token operator">=</span>document<span class="token punctuation">.</span><span class="token function">querySelector</span><span class="token punctuation">(</span><span class="token string">'div'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        div<span class="token punctuation">.</span><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">'mousemove'</span><span class="token punctuation">,</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">e</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token comment">// 获取鼠标距离页面的左边坐标</span>
            <span class="token comment">// 获取当前盒子距离body的左边坐标</span>
            <span class="token comment">// 相减得到鼠标在盒子内的坐标</span>

            <span class="token keyword">var</span> x<span class="token operator">=</span>e<span class="token punctuation">.</span>pageX<span class="token operator">-</span><span class="token keyword">this</span><span class="token punctuation">.</span>offsetLeft<span class="token punctuation">;</span>
            <span class="token keyword">var</span> y<span class="token operator">=</span>e<span class="token punctuation">.</span>pageY<span class="token operator">-</span><span class="token keyword">this</span><span class="token punctuation">.</span>offsetTop<span class="token punctuation">;</span>
            <span class="token keyword">this</span><span class="token punctuation">.</span>innerHTML<span class="token operator">=</span><span class="token string">'x的坐标'</span><span class="token operator">+</span>x<span class="token operator">+</span><span class="token string">',y的坐标'</span><span class="token operator">+</span>y<span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span>
    <span class="token operator">&lt;</span><span class="token operator">/</span>script<span class="token operator">&gt;</span>


</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><h3 id="_32-拖动模态框-编程"><a href="#_32-拖动模态框-编程" class="header-anchor">#</a> 32 拖动模态框（编程）</h3> <h3 id="_33-京东放大镜效果-编程"><a href="#_33-京东放大镜效果-编程" class="header-anchor">#</a> 33 京东放大镜效果(编程)</h3> <h3 id="_34-client系列"><a href="#_34-client系列" class="header-anchor">#</a> 34 client系列</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231741982-482697611.png" alt=""></p> <h3 id="_35-特色事件"><a href="#_35-特色事件" class="header-anchor">#</a> 35 特色事件</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231741120-237695863.png" alt=""></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231740302-1969823667.png" alt=""></p> <h3 id="_36-scroll系列"><a href="#_36-scroll系列" class="header-anchor">#</a> 36 scroll系列</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231739633-1709800950.png" alt=""></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231738801-636116825.png" alt=""></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231738165-242727832.png" alt=""></p> <h3 id="_37-三大系列区别"><a href="#_37-三大系列区别" class="header-anchor">#</a> 37 三大系列区别</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231737621-812114792.png" alt=""></p> <h3 id="_38-mouseenter事件"><a href="#_38-mouseenter事件" class="header-anchor">#</a> 38 mouseenter事件</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231736902-1003022763.png" alt=""></p> <h3 id="_39-缓动函数的封装"><a href="#_39-缓动函数的封装" class="header-anchor">#</a> 39 缓动函数的封装</h3> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">function</span> <span class="token function">animateLow</span><span class="token punctuation">(</span><span class="token parameter">obj<span class="token punctuation">,</span>target<span class="token punctuation">,</span>callback</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token function">clearInterval</span><span class="token punctuation">(</span>obj<span class="token punctuation">.</span>timer<span class="token punctuation">)</span><span class="token punctuation">;</span>
    obj<span class="token punctuation">.</span>timer<span class="token operator">=</span><span class="token function">setInterval</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token comment">// 缓动原理，移动的距离越来越小</span>
        <span class="token comment">// 移动距离=（目标距离-当前移动距离）/10</span>
        <span class="token keyword">var</span> move<span class="token operator">=</span><span class="token punctuation">(</span>target<span class="token operator">-</span>obj<span class="token punctuation">.</span>offsetLeft<span class="token punctuation">)</span><span class="token operator">/</span><span class="token number">10</span><span class="token punctuation">;</span>
        <span class="token comment">// 移动距离取整，往大的方向取</span>
        <span class="token comment">// 移动距离为负数，往小的方向取</span>
        move<span class="token operator">=</span>move<span class="token operator">&gt;=</span><span class="token number">0</span> <span class="token operator">?</span> Math<span class="token punctuation">.</span><span class="token function">ceil</span><span class="token punctuation">(</span>move<span class="token punctuation">)</span> <span class="token operator">:</span> Math<span class="token punctuation">.</span><span class="token function">floor</span><span class="token punctuation">(</span>move<span class="token punctuation">)</span><span class="token punctuation">;</span>
        obj<span class="token punctuation">.</span>style<span class="token punctuation">.</span>left<span class="token operator">=</span>obj<span class="token punctuation">.</span>offsetLeft<span class="token operator">+</span>move<span class="token operator">+</span><span class="token string">'px'</span><span class="token punctuation">;</span>

        <span class="token comment">// 停止</span>
        <span class="token keyword">if</span><span class="token punctuation">(</span>obj<span class="token punctuation">.</span>offsetLeft<span class="token operator">==</span>target<span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token function">clearInterval</span><span class="token punctuation">(</span>obj<span class="token punctuation">.</span>timer<span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token comment">// 定时器的任务执行完毕后</span>
            <span class="token comment">// 执行回调函数</span>
            <span class="token keyword">if</span><span class="token punctuation">(</span>callback<span class="token punctuation">)</span><span class="token punctuation">{</span>
                <span class="token function">callback</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span><span class="token number">15</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>


</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br></div></div><h3 id="_40-轮播图-编程"><a href="#_40-轮播图-编程" class="header-anchor">#</a> 40 轮播图(编程)</h3> <h3 id="_41-轮播图节流阀"><a href="#_41-轮播图节流阀" class="header-anchor">#</a> 41. 轮播图节流阀</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231736426-1354160277.png" alt=""></p> <h3 id="_42-带动画的回到顶部"><a href="#_42-带动画的回到顶部" class="header-anchor">#</a> 42 带动画的回到顶部</h3> <ul><li>window.scroll(x,y)</li></ul> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token operator">&lt;</span><span class="token operator">!</span><span class="token constant">DOCTYPE</span> html<span class="token operator">&gt;</span>
<span class="token operator">&lt;</span>html lang<span class="token operator">=</span><span class="token string">&quot;en&quot;</span><span class="token operator">&gt;</span>

<span class="token operator">&lt;</span>head<span class="token operator">&gt;</span>
    <span class="token operator">&lt;</span>meta charset<span class="token operator">=</span><span class="token string">&quot;UTF-8&quot;</span><span class="token operator">&gt;</span>
    <span class="token operator">&lt;</span>meta name<span class="token operator">=</span><span class="token string">&quot;viewport&quot;</span> content<span class="token operator">=</span><span class="token string">&quot;width=device-width, initial-scale=1.0&quot;</span><span class="token operator">&gt;</span>
    <span class="token operator">&lt;</span>meta http<span class="token operator">-</span>equiv<span class="token operator">=</span><span class="token string">&quot;X-UA-Compatible&quot;</span> content<span class="token operator">=</span><span class="token string">&quot;ie=edge&quot;</span><span class="token operator">&gt;</span>
    <span class="token operator">&lt;</span>title<span class="token operator">&gt;</span>Document<span class="token operator">&lt;</span><span class="token operator">/</span>title<span class="token operator">&gt;</span>
    <span class="token operator">&lt;</span>style<span class="token operator">&gt;</span>
        <span class="token punctuation">.</span>slider<span class="token operator">-</span>bar <span class="token punctuation">{</span>
            <span class="token literal-property property">position</span><span class="token operator">:</span> absolute<span class="token punctuation">;</span>
            <span class="token literal-property property">left</span><span class="token operator">:</span> <span class="token number">50</span><span class="token operator">%</span><span class="token punctuation">;</span>
            <span class="token literal-property property">top</span><span class="token operator">:</span> 300px<span class="token punctuation">;</span>
            margin<span class="token operator">-</span>left<span class="token operator">:</span> 600px<span class="token punctuation">;</span>
            <span class="token literal-property property">width</span><span class="token operator">:</span> 45px<span class="token punctuation">;</span>
            <span class="token literal-property property">height</span><span class="token operator">:</span> 130px<span class="token punctuation">;</span>
            background<span class="token operator">-</span>color<span class="token operator">:</span> pink<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        
        <span class="token punctuation">.</span>w <span class="token punctuation">{</span>
            <span class="token literal-property property">width</span><span class="token operator">:</span> 1200px<span class="token punctuation">;</span>
            <span class="token literal-property property">margin</span><span class="token operator">:</span> 10px auto<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        
        <span class="token punctuation">.</span>header <span class="token punctuation">{</span>
            <span class="token literal-property property">height</span><span class="token operator">:</span> 150px<span class="token punctuation">;</span>
            background<span class="token operator">-</span>color<span class="token operator">:</span> purple<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        
        <span class="token punctuation">.</span>banner <span class="token punctuation">{</span>
            <span class="token literal-property property">height</span><span class="token operator">:</span> 250px<span class="token punctuation">;</span>
            background<span class="token operator">-</span>color<span class="token operator">:</span> skyblue<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        
        <span class="token punctuation">.</span>main <span class="token punctuation">{</span>
            <span class="token literal-property property">height</span><span class="token operator">:</span> 1000px<span class="token punctuation">;</span>
            background<span class="token operator">-</span>color<span class="token operator">:</span> yellowgreen<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        
        span <span class="token punctuation">{</span>
            <span class="token literal-property property">display</span><span class="token operator">:</span> none<span class="token punctuation">;</span>
            <span class="token literal-property property">position</span><span class="token operator">:</span> absolute<span class="token punctuation">;</span>
            <span class="token literal-property property">bottom</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token operator">&lt;</span><span class="token operator">/</span>style<span class="token operator">&gt;</span>
<span class="token operator">&lt;</span><span class="token operator">/</span>head<span class="token operator">&gt;</span>

<span class="token operator">&lt;</span>body<span class="token operator">&gt;</span>
    <span class="token operator">&lt;</span>div <span class="token keyword">class</span><span class="token operator">=</span><span class="token string">&quot;slider-bar&quot;</span><span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span>span <span class="token keyword">class</span><span class="token operator">=</span><span class="token string">&quot;goBack&quot;</span><span class="token operator">&gt;</span>返回顶部<span class="token operator">&lt;</span><span class="token operator">/</span>span<span class="token operator">&gt;</span>
    <span class="token operator">&lt;</span><span class="token operator">/</span>div<span class="token operator">&gt;</span>
    <span class="token operator">&lt;</span>div <span class="token keyword">class</span><span class="token operator">=</span><span class="token string">&quot;header w&quot;</span><span class="token operator">&gt;</span>头部区域<span class="token operator">&lt;</span><span class="token operator">/</span>div<span class="token operator">&gt;</span>
    <span class="token operator">&lt;</span>div <span class="token keyword">class</span><span class="token operator">=</span><span class="token string">&quot;banner w&quot;</span><span class="token operator">&gt;</span>banner区域<span class="token operator">&lt;</span><span class="token operator">/</span>div<span class="token operator">&gt;</span>
    <span class="token operator">&lt;</span>div <span class="token keyword">class</span><span class="token operator">=</span><span class="token string">&quot;main w&quot;</span><span class="token operator">&gt;</span>主体部分<span class="token operator">&lt;</span><span class="token operator">/</span>div<span class="token operator">&gt;</span>

    <span class="token operator">&lt;</span>script<span class="token operator">&gt;</span>
        <span class="token comment">// 获取banner</span>
        <span class="token keyword">var</span> banner<span class="token operator">=</span>document<span class="token punctuation">.</span><span class="token function">querySelector</span><span class="token punctuation">(</span><span class="token string">'.banner'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">var</span> sliderbar<span class="token operator">=</span>document<span class="token punctuation">.</span><span class="token function">querySelector</span><span class="token punctuation">(</span><span class="token string">'.slider-bar'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">var</span> bannerTop<span class="token operator">=</span>banner<span class="token punctuation">.</span>offsetTop<span class="token punctuation">;</span>
        <span class="token comment">// 固定定位后的距离</span>
        <span class="token keyword">var</span> sliderTop<span class="token operator">=</span>sliderbar<span class="token punctuation">.</span>offsetTop<span class="token operator">-</span>bannerTop<span class="token punctuation">;</span>

        <span class="token comment">// 获取main</span>
        <span class="token keyword">var</span> main<span class="token operator">=</span>document<span class="token punctuation">.</span><span class="token function">querySelector</span><span class="token punctuation">(</span><span class="token string">'.main'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">var</span> mainTop<span class="token operator">=</span>main<span class="token punctuation">.</span>offsetTop<span class="token punctuation">;</span>
        <span class="token comment">// 获取回到顶部</span>
        <span class="token keyword">var</span> goBack<span class="token operator">=</span>document<span class="token punctuation">.</span><span class="token function">querySelector</span><span class="token punctuation">(</span><span class="token string">'.goBack'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">// 当页面被卷去的距离为banner区域的offsetTop时，滚动导航栏变为固定单位</span>
        document<span class="token punctuation">.</span><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">'scroll'</span><span class="token punctuation">,</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            
            
            <span class="token keyword">if</span><span class="token punctuation">(</span>window<span class="token punctuation">.</span>pageYOffset<span class="token operator">&gt;=</span>bannerTop<span class="token punctuation">)</span><span class="token punctuation">{</span>
                sliderbar<span class="token punctuation">.</span>style<span class="token punctuation">.</span>position<span class="token operator">=</span><span class="token string">'fixed'</span><span class="token punctuation">;</span>
                sliderbar<span class="token punctuation">.</span>style<span class="token punctuation">.</span>top<span class="token operator">=</span>sliderTop<span class="token operator">+</span><span class="token string">'px'</span><span class="token punctuation">;</span>

            <span class="token punctuation">}</span><span class="token keyword">else</span><span class="token punctuation">{</span>
                sliderbar<span class="token punctuation">.</span>style<span class="token punctuation">.</span>position<span class="token operator">=</span><span class="token string">'absolute'</span><span class="token punctuation">;</span>
                sliderbar<span class="token punctuation">.</span>style<span class="token punctuation">.</span>top<span class="token operator">=</span><span class="token string">'300px'</span><span class="token punctuation">;</span> 
            <span class="token punctuation">}</span>

            <span class="token keyword">if</span><span class="token punctuation">(</span>window<span class="token punctuation">.</span>pageYOffset<span class="token operator">&gt;=</span>mainTop<span class="token punctuation">)</span><span class="token punctuation">{</span>
                goBack<span class="token punctuation">.</span>style<span class="token punctuation">.</span>display<span class="token operator">=</span><span class="token string">'block'</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span><span class="token keyword">else</span><span class="token punctuation">{</span>
                goBack<span class="token punctuation">.</span>style<span class="token punctuation">.</span>display<span class="token operator">=</span><span class="token string">'none'</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>

            goBack<span class="token punctuation">.</span><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">'click'</span><span class="token punctuation">,</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                <span class="token comment">// window.scroll使窗口滚动到顶部</span>
                <span class="token comment">// window.scroll(0,0);</span>

                <span class="token comment">// 2.使用缓动函数实现带动画的回到顶部</span>
                <span class="token function">animateLow</span><span class="token punctuation">(</span>window<span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token punctuation">}</span><span class="token punctuation">)</span>


            <span class="token keyword">function</span> <span class="token function">animateLow</span><span class="token punctuation">(</span><span class="token parameter">obj<span class="token punctuation">,</span>target<span class="token punctuation">,</span>callback</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                <span class="token function">clearInterval</span><span class="token punctuation">(</span>obj<span class="token punctuation">.</span>timer<span class="token punctuation">)</span><span class="token punctuation">;</span>
                obj<span class="token punctuation">.</span>timer<span class="token operator">=</span><span class="token function">setInterval</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                    <span class="token comment">// 缓动原理，移动的距离越来越小</span>
                    <span class="token comment">// 移动距离=（目标距离-当前移动距离）/10</span>
                    <span class="token keyword">var</span> move<span class="token operator">=</span><span class="token punctuation">(</span>target<span class="token operator">-</span>obj<span class="token punctuation">.</span>pageYOffset<span class="token punctuation">)</span><span class="token operator">/</span><span class="token number">10</span><span class="token punctuation">;</span>
                    <span class="token comment">// 移动距离取整，往大的方向取</span>
                    <span class="token comment">// 移动距离为负数，往小的方向取</span>
                    move<span class="token operator">=</span>move<span class="token operator">&gt;=</span><span class="token number">0</span> <span class="token operator">?</span> Math<span class="token punctuation">.</span><span class="token function">ceil</span><span class="token punctuation">(</span>move<span class="token punctuation">)</span> <span class="token operator">:</span> Math<span class="token punctuation">.</span><span class="token function">floor</span><span class="token punctuation">(</span>move<span class="token punctuation">)</span><span class="token punctuation">;</span>
                    <span class="token comment">// obj.style.left=obj.offsetLeft+move+'px';</span>
                    obj<span class="token punctuation">.</span><span class="token function">scroll</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span>move<span class="token operator">+</span>obj<span class="token punctuation">.</span>pageYOffset<span class="token punctuation">)</span><span class="token punctuation">;</span>

                    <span class="token comment">// 停止</span>
                    <span class="token keyword">if</span><span class="token punctuation">(</span>obj<span class="token punctuation">.</span>pageYOffset<span class="token operator">==</span>target<span class="token punctuation">)</span><span class="token punctuation">{</span>
                        <span class="token function">clearInterval</span><span class="token punctuation">(</span>obj<span class="token punctuation">.</span>timer<span class="token punctuation">)</span><span class="token punctuation">;</span>

                        <span class="token comment">// 定时器的任务执行完毕后</span>
                        <span class="token comment">// 执行回调函数</span>
                        <span class="token keyword">if</span><span class="token punctuation">(</span>callback<span class="token punctuation">)</span><span class="token punctuation">{</span>
                            <span class="token function">callback</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                        <span class="token punctuation">}</span>
                        
                    <span class="token punctuation">}</span>
                <span class="token punctuation">}</span><span class="token punctuation">,</span><span class="token number">15</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>

        <span class="token punctuation">}</span><span class="token punctuation">)</span>
        
    <span class="token operator">&lt;</span><span class="token operator">/</span>script<span class="token operator">&gt;</span>
    
<span class="token operator">&lt;</span><span class="token operator">/</span>body<span class="token operator">&gt;</span>

<span class="token operator">&lt;</span><span class="token operator">/</span>html<span class="token operator">&gt;</span>

</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br><span class="line-number">46</span><br><span class="line-number">47</span><br><span class="line-number">48</span><br><span class="line-number">49</span><br><span class="line-number">50</span><br><span class="line-number">51</span><br><span class="line-number">52</span><br><span class="line-number">53</span><br><span class="line-number">54</span><br><span class="line-number">55</span><br><span class="line-number">56</span><br><span class="line-number">57</span><br><span class="line-number">58</span><br><span class="line-number">59</span><br><span class="line-number">60</span><br><span class="line-number">61</span><br><span class="line-number">62</span><br><span class="line-number">63</span><br><span class="line-number">64</span><br><span class="line-number">65</span><br><span class="line-number">66</span><br><span class="line-number">67</span><br><span class="line-number">68</span><br><span class="line-number">69</span><br><span class="line-number">70</span><br><span class="line-number">71</span><br><span class="line-number">72</span><br><span class="line-number">73</span><br><span class="line-number">74</span><br><span class="line-number">75</span><br><span class="line-number">76</span><br><span class="line-number">77</span><br><span class="line-number">78</span><br><span class="line-number">79</span><br><span class="line-number">80</span><br><span class="line-number">81</span><br><span class="line-number">82</span><br><span class="line-number">83</span><br><span class="line-number">84</span><br><span class="line-number">85</span><br><span class="line-number">86</span><br><span class="line-number">87</span><br><span class="line-number">88</span><br><span class="line-number">89</span><br><span class="line-number">90</span><br><span class="line-number">91</span><br><span class="line-number">92</span><br><span class="line-number">93</span><br><span class="line-number">94</span><br><span class="line-number">95</span><br><span class="line-number">96</span><br><span class="line-number">97</span><br><span class="line-number">98</span><br><span class="line-number">99</span><br><span class="line-number">100</span><br><span class="line-number">101</span><br><span class="line-number">102</span><br><span class="line-number">103</span><br><span class="line-number">104</span><br><span class="line-number">105</span><br><span class="line-number">106</span><br><span class="line-number">107</span><br><span class="line-number">108</span><br><span class="line-number">109</span><br><span class="line-number">110</span><br><span class="line-number">111</span><br><span class="line-number">112</span><br><span class="line-number">113</span><br><span class="line-number">114</span><br><span class="line-number">115</span><br><span class="line-number">116</span><br><span class="line-number">117</span><br><span class="line-number">118</span><br><span class="line-number">119</span><br><span class="line-number">120</span><br><span class="line-number">121</span><br><span class="line-number">122</span><br><span class="line-number">123</span><br><span class="line-number">124</span><br><span class="line-number">125</span><br><span class="line-number">126</span><br><span class="line-number">127</span><br><span class="line-number">128</span><br><span class="line-number">129</span><br><span class="line-number">130</span><br><span class="line-number">131</span><br></div></div><h3 id="_43-移动端触屏特效"><a href="#_43-移动端触屏特效" class="header-anchor">#</a> 43. 移动端触屏特效</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231736018-150127573.png" alt=""></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231735564-1327347481.png" alt="QQ截图20230117110156"></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231734679-675169581.png" alt="QQ截图20230117110225"></p> <h3 id="_44-移动端轮播图"><a href="#_44-移动端轮播图" class="header-anchor">#</a> 44 移动端轮播图</h3> <ul><li>不同点：前后都复制了一张图片</li> <li>不使用定位，直接使用了translate</li> <li>使用了过渡完成的事件transitionend</li></ul> <div class="language-js line-numbers-mode"><pre class="language-js"><code>window<span class="token punctuation">.</span><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">'load'</span><span class="token punctuation">,</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token comment">// alert(11);</span>

    <span class="token keyword">var</span> banner<span class="token operator">=</span><span class="token keyword">this</span><span class="token punctuation">.</span>document<span class="token punctuation">.</span><span class="token function">querySelector</span><span class="token punctuation">(</span><span class="token string">'.banner'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">// console.log(banner);</span>

    <span class="token keyword">var</span> ul<span class="token operator">=</span>banner<span class="token punctuation">.</span><span class="token function">querySelector</span><span class="token punctuation">(</span><span class="token string">'ul'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">var</span> ol<span class="token operator">=</span>banner<span class="token punctuation">.</span><span class="token function">querySelector</span><span class="token punctuation">(</span><span class="token string">'ol'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">// 循环创建轮播小圆点</span>
    <span class="token keyword">for</span><span class="token punctuation">(</span><span class="token keyword">var</span> i<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">;</span>i<span class="token operator">&lt;</span>ul<span class="token punctuation">.</span>children<span class="token punctuation">.</span>length<span class="token punctuation">;</span>i<span class="token operator">++</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">var</span> li<span class="token operator">=</span><span class="token keyword">this</span><span class="token punctuation">.</span>document<span class="token punctuation">.</span><span class="token function">createElement</span><span class="token punctuation">(</span><span class="token string">'li'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        li<span class="token punctuation">.</span><span class="token function">setAttribute</span><span class="token punctuation">(</span><span class="token string">'index'</span><span class="token punctuation">,</span>i<span class="token punctuation">)</span><span class="token punctuation">;</span>
        ol<span class="token punctuation">.</span><span class="token function">appendChild</span><span class="token punctuation">(</span>li<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token comment">// 第一张图片设置current属性</span>

    ol<span class="token punctuation">.</span>children<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">.</span>className<span class="token operator">=</span><span class="token string">'current'</span><span class="token punctuation">;</span>

    <span class="token comment">// 移动端与pc端的无缝轮播有区别，防止第一张左滑留白，第一张前面也添加一张图片</span>

    <span class="token keyword">var</span> copy1<span class="token operator">=</span>ul<span class="token punctuation">.</span>children<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">cloneNode</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">var</span> copy2<span class="token operator">=</span>ul<span class="token punctuation">.</span>children<span class="token punctuation">[</span>ul<span class="token punctuation">.</span>children<span class="token punctuation">.</span>length<span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">cloneNode</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    ul<span class="token punctuation">.</span><span class="token function">appendChild</span><span class="token punctuation">(</span>copy1<span class="token punctuation">)</span><span class="token punctuation">;</span>
    ul<span class="token punctuation">.</span><span class="token function">insertBefore</span><span class="token punctuation">(</span>copy2<span class="token punctuation">,</span>ul<span class="token punctuation">.</span>children<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>



    <span class="token comment">// 设置图片自动滚动，定时器+css3的位移（translate）</span>

    <span class="token comment">// 获取焦点图盒子的大小</span>
    <span class="token keyword">var</span> b_width<span class="token operator">=</span>banner<span class="token punctuation">.</span>clientWidth<span class="token punctuation">;</span>
    <span class="token comment">// console.log(b_width);</span>

    <span class="token keyword">var</span> index<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">;</span>
    <span class="token keyword">var</span> timer<span class="token operator">=</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">setInterval</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        index<span class="token operator">++</span><span class="token punctuation">;</span>

        <span class="token comment">// 设置transform过渡</span>
        ul<span class="token punctuation">.</span>style<span class="token punctuation">.</span>transition<span class="token operator">=</span><span class="token string">'all .3s'</span><span class="token punctuation">;</span>
        ul<span class="token punctuation">.</span>style<span class="token punctuation">.</span>transform<span class="token operator">=</span><span class="token string">'translateX('</span><span class="token operator">+</span><span class="token punctuation">(</span><span class="token operator">-</span>b_width<span class="token operator">*</span>index<span class="token punctuation">)</span> <span class="token operator">+</span><span class="token string">'px)'</span>


        
    <span class="token punctuation">}</span><span class="token punctuation">,</span><span class="token number">2000</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    
    <span class="token comment">// 判断过渡是否完成，如果完成，在执行操作</span>
    ul<span class="token punctuation">.</span><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">'transitionend'</span><span class="token punctuation">,</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">// 无缝滚动</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>index <span class="token operator">&gt;=</span> <span class="token number">3</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            index <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
            <span class="token comment">// console.log(index);</span>
            <span class="token comment">// 去掉过渡效果 这样让我们的ul 快速的跳到目标位置</span>
            ul<span class="token punctuation">.</span>style<span class="token punctuation">.</span>transition <span class="token operator">=</span> <span class="token string">'none'</span><span class="token punctuation">;</span>
            <span class="token comment">// 利用最新的索引号乘以宽度 去滚动图片</span>
            <span class="token keyword">var</span> translatex <span class="token operator">=</span> <span class="token operator">-</span>index <span class="token operator">*</span> b_width<span class="token punctuation">;</span>
            ul<span class="token punctuation">.</span>style<span class="token punctuation">.</span>transform <span class="token operator">=</span> <span class="token string">'translateX('</span> <span class="token operator">+</span> translatex <span class="token operator">+</span> <span class="token string">'px)'</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>index <span class="token operator">&lt;</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            index <span class="token operator">=</span> <span class="token number">2</span><span class="token punctuation">;</span>
            ul<span class="token punctuation">.</span>style<span class="token punctuation">.</span>transition <span class="token operator">=</span> <span class="token string">'none'</span><span class="token punctuation">;</span>
            <span class="token comment">// 利用最新的索引号乘以宽度 去滚动图片</span>
            <span class="token keyword">var</span> translatex <span class="token operator">=</span> <span class="token operator">-</span>index <span class="token operator">*</span> b_width<span class="token punctuation">;</span>
            ul<span class="token punctuation">.</span>style<span class="token punctuation">.</span>transform <span class="token operator">=</span> <span class="token string">'translateX('</span> <span class="token operator">+</span> translatex <span class="token operator">+</span> <span class="token string">'px)'</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        <span class="token comment">// 在过渡接收后检测小圆点的变化</span>
        <span class="token comment">// 去除当前的小圆点，实现小圆点切换</span>
        ol<span class="token punctuation">.</span><span class="token function">querySelector</span><span class="token punctuation">(</span><span class="token string">'li.current'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>classList<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span><span class="token string">'current'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        ol<span class="token punctuation">.</span>children<span class="token punctuation">[</span>index<span class="token punctuation">]</span><span class="token punctuation">.</span>classList<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token string">'current'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span>

    <span class="token comment">// 手指滑动实现轮播图切换</span>
    <span class="token keyword">var</span> mouseX<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">;</span>
    <span class="token keyword">var</span> moveX<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">;</span>
    <span class="token keyword">var</span> liStep<span class="token operator">=</span>ul<span class="token punctuation">.</span>children<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">.</span>clientWidth<span class="token operator">/</span><span class="token number">7</span><span class="token punctuation">;</span>

    <span class="token comment">// 定义一个变量判断用户是否移动</span>
    <span class="token keyword">var</span> touch<span class="token operator">=</span><span class="token boolean">false</span><span class="token punctuation">;</span>
    ul<span class="token punctuation">.</span><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">'touchstart'</span><span class="token punctuation">,</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">e</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token comment">// 手指摸上去，停止计时器</span>
        <span class="token function">clearInterval</span><span class="token punctuation">(</span>timer<span class="token punctuation">)</span><span class="token punctuation">;</span>
        timer<span class="token operator">=</span><span class="token keyword">null</span><span class="token punctuation">;</span>
        mouseX<span class="token operator">=</span>e<span class="token punctuation">.</span>targetTouches<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">.</span>pageX<span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span>

    <span class="token comment">// 手指滑动轮播图</span>
    ul<span class="token punctuation">.</span><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">'touchmove'</span><span class="token punctuation">,</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">e</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token comment">// 鼠标的移动距离</span>
        moveX<span class="token operator">=</span>e<span class="token punctuation">.</span>targetTouches<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">.</span>pageX<span class="token operator">-</span>mouseX<span class="token punctuation">;</span>
        <span class="token comment">// translateX的距离</span>
        
        <span class="token keyword">var</span> translatex<span class="token operator">=</span><span class="token punctuation">(</span><span class="token operator">-</span>b_width<span class="token operator">*</span>index<span class="token punctuation">)</span><span class="token operator">+</span>moveX<span class="token punctuation">;</span>
        ul<span class="token punctuation">.</span>style<span class="token punctuation">.</span>transform <span class="token operator">=</span> <span class="token string">'translateX('</span> <span class="token operator">+</span> translatex <span class="token operator">+</span> <span class="token string">'px)'</span><span class="token punctuation">;</span>
        touch<span class="token operator">=</span><span class="token boolean">true</span><span class="token punctuation">;</span>

        <span class="token comment">// 取消默认滚动屏幕行为</span>
        e<span class="token punctuation">.</span><span class="token function">preventDefault</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token punctuation">}</span><span class="token punctuation">)</span>

    ul<span class="token punctuation">.</span><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">'touchend'</span><span class="token punctuation">,</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>

        <span class="token keyword">if</span><span class="token punctuation">(</span>touch<span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token keyword">if</span><span class="token punctuation">(</span>Math<span class="token punctuation">.</span><span class="token function">abs</span><span class="token punctuation">(</span>moveX<span class="token punctuation">)</span><span class="token operator">&gt;</span>liStep<span class="token punctuation">)</span><span class="token punctuation">{</span>
                <span class="token comment">//  大于0，播放上一张</span>
                <span class="token keyword">if</span><span class="token punctuation">(</span>moveX<span class="token operator">&gt;</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                    index<span class="token operator">--</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span><span class="token keyword">else</span> <span class="token keyword">if</span><span class="token punctuation">(</span>moveX<span class="token operator">&lt;</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                    <span class="token comment">// 播放下一张</span>
                    index<span class="token operator">++</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span>
    
            <span class="token punctuation">}</span>
            <span class="token keyword">var</span> translatex<span class="token operator">=</span><span class="token operator">-</span>index<span class="token operator">*</span>b_width<span class="token punctuation">;</span>
            ul<span class="token punctuation">.</span>style<span class="token punctuation">.</span>transition<span class="token operator">=</span><span class="token string">'all .3s'</span><span class="token punctuation">;</span>
            ul<span class="token punctuation">.</span>style<span class="token punctuation">.</span>transform <span class="token operator">=</span> <span class="token string">'translateX('</span> <span class="token operator">+</span> translatex <span class="token operator">+</span> <span class="token string">'px)'</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        
        <span class="token comment">// 手指离开，定时器开始</span>
        timer<span class="token operator">=</span><span class="token function">setInterval</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            index<span class="token operator">++</span><span class="token punctuation">;</span>
    
            <span class="token comment">// 设置transform过渡</span>
            ul<span class="token punctuation">.</span>style<span class="token punctuation">.</span>transition<span class="token operator">=</span><span class="token string">'all .3s'</span><span class="token punctuation">;</span>
            ul<span class="token punctuation">.</span>style<span class="token punctuation">.</span>transform<span class="token operator">=</span><span class="token string">'translateX('</span><span class="token operator">+</span><span class="token punctuation">(</span><span class="token operator">-</span>b_width<span class="token operator">*</span>index<span class="token punctuation">)</span> <span class="token operator">+</span><span class="token string">'px)'</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span><span class="token number">2000</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span>
    
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br><span class="line-number">46</span><br><span class="line-number">47</span><br><span class="line-number">48</span><br><span class="line-number">49</span><br><span class="line-number">50</span><br><span class="line-number">51</span><br><span class="line-number">52</span><br><span class="line-number">53</span><br><span class="line-number">54</span><br><span class="line-number">55</span><br><span class="line-number">56</span><br><span class="line-number">57</span><br><span class="line-number">58</span><br><span class="line-number">59</span><br><span class="line-number">60</span><br><span class="line-number">61</span><br><span class="line-number">62</span><br><span class="line-number">63</span><br><span class="line-number">64</span><br><span class="line-number">65</span><br><span class="line-number">66</span><br><span class="line-number">67</span><br><span class="line-number">68</span><br><span class="line-number">69</span><br><span class="line-number">70</span><br><span class="line-number">71</span><br><span class="line-number">72</span><br><span class="line-number">73</span><br><span class="line-number">74</span><br><span class="line-number">75</span><br><span class="line-number">76</span><br><span class="line-number">77</span><br><span class="line-number">78</span><br><span class="line-number">79</span><br><span class="line-number">80</span><br><span class="line-number">81</span><br><span class="line-number">82</span><br><span class="line-number">83</span><br><span class="line-number">84</span><br><span class="line-number">85</span><br><span class="line-number">86</span><br><span class="line-number">87</span><br><span class="line-number">88</span><br><span class="line-number">89</span><br><span class="line-number">90</span><br><span class="line-number">91</span><br><span class="line-number">92</span><br><span class="line-number">93</span><br><span class="line-number">94</span><br><span class="line-number">95</span><br><span class="line-number">96</span><br><span class="line-number">97</span><br><span class="line-number">98</span><br><span class="line-number">99</span><br><span class="line-number">100</span><br><span class="line-number">101</span><br><span class="line-number">102</span><br><span class="line-number">103</span><br><span class="line-number">104</span><br><span class="line-number">105</span><br><span class="line-number">106</span><br><span class="line-number">107</span><br><span class="line-number">108</span><br><span class="line-number">109</span><br><span class="line-number">110</span><br><span class="line-number">111</span><br><span class="line-number">112</span><br><span class="line-number">113</span><br><span class="line-number">114</span><br><span class="line-number">115</span><br><span class="line-number">116</span><br><span class="line-number">117</span><br><span class="line-number">118</span><br><span class="line-number">119</span><br><span class="line-number">120</span><br><span class="line-number">121</span><br><span class="line-number">122</span><br><span class="line-number">123</span><br><span class="line-number">124</span><br><span class="line-number">125</span><br><span class="line-number">126</span><br><span class="line-number">127</span><br><span class="line-number">128</span><br><span class="line-number">129</span><br><span class="line-number">130</span><br></div></div><h3 id="_45-classlist"><a href="#_45-classlist" class="header-anchor">#</a> 45 classList</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231734189-1511587483.png" alt=""></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231733644-640265517.png" alt="QQ截图20230117163924"></p> <ul><li>排他思想更容易实现</li></ul> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">// 在过渡接收后检测小圆点的变化</span>
        <span class="token comment">// 去除当前的小圆点，实现小圆点切换</span>
        ol<span class="token punctuation">.</span><span class="token function">querySelector</span><span class="token punctuation">(</span><span class="token string">'li.current'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>classList<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span><span class="token string">'current'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        ol<span class="token punctuation">.</span>children<span class="token punctuation">[</span>index<span class="token punctuation">]</span><span class="token punctuation">.</span>classList<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token string">'current'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h3 id="_46-双击延时解决方案"><a href="#_46-双击延时解决方案" class="header-anchor">#</a> 46 双击延时解决方案</h3> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">//封装tap，解决click 300ms 延时</span>
<span class="token keyword">function</span> <span class="token function">tap</span> <span class="token punctuation">(</span><span class="token parameter">obj<span class="token punctuation">,</span> callback</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
 <span class="token keyword">var</span> isMove <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
 <span class="token keyword">var</span> startTime <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> <span class="token comment">// 记录触摸时候的时间变量</span>
 obj<span class="token punctuation">.</span><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">'touchstart'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token parameter">e</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
 startTime <span class="token operator">=</span> Date<span class="token punctuation">.</span><span class="token function">now</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 记录触摸时间</span>
 <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
 obj<span class="token punctuation">.</span><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">'touchmove'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token parameter">e</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
 isMove <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span> <span class="token comment">// 看看是否有滑动，有滑动算拖拽，不算点击</span>
 <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
 obj<span class="token punctuation">.</span><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">'touchend'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token parameter">e</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
 <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>isMove <span class="token operator">&amp;&amp;</span> <span class="token punctuation">(</span>Date<span class="token punctuation">.</span><span class="token function">now</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">-</span> startTime<span class="token punctuation">)</span> <span class="token operator">&lt;</span> <span class="token number">150</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token comment">// 如果手指触摸和离开时间小于150ms 算点击</span>
 callback <span class="token operator">&amp;&amp;</span> <span class="token function">callback</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 执行回调函数</span>
 <span class="token punctuation">}</span>
 isMove <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">;</span> <span class="token comment">// 取反 重置</span>
 startTime <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
 <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token comment">//调用 </span>
 <span class="token function">tap</span><span class="token punctuation">(</span>div<span class="token punctuation">,</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span> <span class="token comment">// 执行代码 });</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br></div></div><h3 id="_47-本地存储"><a href="#_47-本地存储" class="header-anchor">#</a> 47 本地存储</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231733253-1246877806.png" alt=""></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231732959-365040403.png" alt="QQ截图20230117172502"></p> <h3 id="_48-jquery入口函数"><a href="#_48-jquery入口函数" class="header-anchor">#</a> 48 jquery入口函数</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231732658-1261637473.png" alt=""></p> <h3 id="_49-jquery和dom的转换"><a href="#_49-jquery和dom的转换" class="header-anchor">#</a> 49 jquery和dom的转换</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231732214-2103612841.png" alt="QQ截图20230117203700"></p> <h3 id="_50-jquery选择器"><a href="#_50-jquery选择器" class="header-anchor">#</a> 50 jquery选择器</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231731751-1506348312.png" alt=""></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231731211-843835790.png" alt="QQ截图20230117204356"></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231730481-1244034160.png" alt="QQ截图20230117204411"></p> <h3 id="_51-jquery设置样式"><a href="#_51-jquery设置样式" class="header-anchor">#</a> 51 jquery设置样式</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231729959-394816810.png" alt=""></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231729660-180759054.png" alt=""></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231729188-83193638.png" alt="QQ截图20230117210458"></p> <h3 id="_52-jquery排他思想"><a href="#_52-jquery排他思想" class="header-anchor">#</a> 52 jquery排他思想</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231728776-335734358.png" alt=""></p> <h3 id="_53-jquery获取当前元素索引号"><a href="#_53-jquery获取当前元素索引号" class="header-anchor">#</a> 53 jquery获取当前元素索引号</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231728399-1908176511.png" alt=""></p> <h3 id="_54-jquery链式编程"><a href="#_54-jquery链式编程" class="header-anchor">#</a> 54 jquery链式编程</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231728022-1850875789.png" alt=""></p> <h3 id="_55-jquery动画效果"><a href="#_55-jquery动画效果" class="header-anchor">#</a> 55 jQuery动画效果</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231727694-1624332543.png" alt=""></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231727202-1109899846.png" alt=""></p> <ul><li>其他动画效果的参数也大致相同</li></ul> <h3 id="_56-jquery事件切换-即mouseover和mouseout的结合体"><a href="#_56-jquery事件切换-即mouseover和mouseout的结合体" class="header-anchor">#</a> 56 jquery事件切换，即mouseover和mouseout的结合体</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231726674-1174762690.png" alt=""></p> <h3 id="_57-jquery-stop"><a href="#_57-jquery-stop" class="header-anchor">#</a> 57 jquery stop</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231726263-1811774404.png" alt=""></p> <h3 id="_58-jquery属性操作"><a href="#_58-jquery属性操作" class="header-anchor">#</a> 58 jquery属性操作</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231725810-83161719.png" alt="QQ截图20230118095031"></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231725364-553124920.png" alt="QQ截图20230118095043"></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231724891-255957266.png" alt="QQ截图20230118095124"></p> <ul><li>data-index自定义属性获取，data(&quot;index&quot;)</li></ul> <h3 id="_59-jquery内容文本值"><a href="#_59-jquery内容文本值" class="header-anchor">#</a> 59 jquery内容文本值</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231724444-690279101.png" alt=""></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231723999-1348821085.png" alt="QQ截图20230118101317"></p> <h3 id="_60-jquery祖先选择器"><a href="#_60-jquery祖先选择器" class="header-anchor">#</a> 60 jquery祖先选择器</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231723605-436934022.png" alt=""></p> <h3 id="_61-jquery遍历元素"><a href="#_61-jquery遍历元素" class="header-anchor">#</a> 61 jquery遍历元素</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231723279-1976087325.png" alt=""></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231722722-410733030.png" alt="QQ截图20230118102852"></p> <h3 id="_62-jquery节点操作"><a href="#_62-jquery节点操作" class="header-anchor">#</a> 62 jquery节点操作</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231722298-1672700705.png" alt=""></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231721891-43346615.png" alt="QQ截图20230118103659"></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231721410-170399429.png" alt="QQ截图20230118103729"></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231720890-1961351633.png" alt="QQ截图20230118103816"></p> <h3 id="_63-jquery位置"><a href="#_63-jquery位置" class="header-anchor">#</a> 63 jquery位置</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231720421-936406577.png" alt=""></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231719828-83657223.png" alt="QQ截图20230118104554"></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231719424-1040885699.png" alt="QQ截图20230118104603"></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231718937-501124907.png" alt="QQ截图20230118104626"></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231718572-1084668559.png" alt="QQ截图20230118105139"></p> <h3 id="_64-jquery实现返回顶部"><a href="#_64-jquery实现返回顶部" class="header-anchor">#</a> 64 jQuery实现返回顶部</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231718015-2059178288.png" alt=""></p> <h3 id="_65-jquery事件"><a href="#_65-jquery事件" class="header-anchor">#</a> 65 jquery事件</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231717639-611948614.png" alt=""></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231717193-433159599.png" alt="QQ截图20230118110557"></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231716687-204398863.png" alt="QQ截图20230118110622"></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231716150-718697887.png" alt="QQ截图20230118110642"></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231715646-156226248.png" alt="QQ截图20230118110658"></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231715149-487423554.png" alt="QQ截图20230118110718"></p> <h3 id="_66-jquery自动触发事件"><a href="#_66-jquery自动触发事件" class="header-anchor">#</a> 66 jquery自动触发事件</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231714657-1542302158.png" alt=""></p> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231714198-1985344392.png" alt="QQ截图20230118111805"></p> <h3 id="_67-jquery事件对象"><a href="#_67-jquery事件对象" class="header-anchor">#</a> 67 jquery事件对象</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231713612-1724146179.png" alt=""></p> <h3 id="_68-jquery对象拷贝"><a href="#_68-jquery对象拷贝" class="header-anchor">#</a> 68 jquery对象拷贝</h3> <p><img src="https://img2023.cnblogs.com/blog/3089561/202302/3089561-20230202231713138-152612820.png" alt=""></p></div></div>  <div class="page-edit"><div class="edit-link"><a href="https://github.com/linxin1123/vuepress-blog/edit/master/docs/08.面试/01.蓝桥杯备战/02.Dom和Bom复习-cnblog.md" target="_blank" rel="noopener noreferrer">编辑</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <!----> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2023/02/17, 11:29:32</span></div></div> <div class="page-nav-wapper"><div class="page-nav-centre-wrap"><a href="/pages/fc8666/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">html+css部分复习-cnblog</div></a> <a href="/pages/e4078d/" class="page-nav-centre page-nav-centre-next"><div class="tooltip">ajax复习</div></a></div> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/pages/fc8666/" class="prev">html+css部分复习-cnblog</a></span> <span class="next"><a href="/pages/e4078d/">ajax复习</a>→
      </span></p></div></div></div> <div class="article-list"><div class="article-title"><a href="/archives/" class="iconfont icon-bi">最近更新</a></div> <div class="article-wrapper"><dl><dd>01</dd> <dt><a href="/pages/0b785d/"><div>
            Vuex
            <!----></div></a> <span class="date">03-14</span></dt></dl><dl><dd>02</dd> <dt><a href="/pages/c59cc0/"><div>
            Vue响应式原理
            <!----></div></a> <span class="date">03-14</span></dt></dl><dl><dd>03</dd> <dt><a href="/pages/83cc7a/"><div>
            Vue虚拟DOM-cnblog
            <!----></div></a> <span class="date">03-14</span></dt></dl> <dl><dd></dd> <dt><a href="/archives/" class="more">更多文章&gt;</a></dt></dl></div></div></main></div> <div class="footer"><div class="icons"><a href="3010733382@qq.com" title="发邮件" target="_blank" class="iconfont icon-youjian"></a><a href="https://github.com/linxin1123" title="GitHub" target="_blank" class="iconfont icon-github"></a><a href="https://music.163.com/#/playlist?id=755597173" title="听音乐" target="_blank" class="iconfont icon-erji"></a></div> 
  Theme by
  <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" title="本站主题">Vdoing</a> 
    | Copyright © 2022-2023
    <span>lingxin | <a href="https://github.com/linxin1123/vuepress-blog/blob/master/LICENSE" target="_blank">MIT License</a></span></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div> <div title="主题模式" class="button blur theme-mode-but iconfont icon-zhuti"><ul class="select-box" style="display:none;"><li class="iconfont icon-zidong">
          跟随系统
        </li><li class="iconfont icon-rijianmoshi">
          浅色模式
        </li><li class="iconfont icon-yejianmoshi">
          深色模式
        </li><li class="iconfont icon-yuedu">
          阅读模式
        </li></ul></div></div> <!----> <!----> <!----></div><div class="global-ui"><div></div></div></div>
    <script src="/assets/js/app.57550e13.js" defer></script><script src="/assets/js/2.f014c35f.js" defer></script><script src="/assets/js/125.f073ab1c.js" defer></script>
  </body>
</html>
